//
//  CollectingViewController.m
//  PerfectWorld
//
//  Created by dllo on 16/9/24.
//  Copyright © 2016年 LST. All rights reserved.
//

#import "CollectingViewController.h"
#import "DCNavTabBarController.h"
#import "NetworkHandler.h"
#import "OneTableView.h"
#import "TwoTableView.h"
@interface CollectingViewController ()<UIScrollViewDelegate, PressTableViewCellDelegate, PressTwoTableViewCellDelegate>
@property (nonatomic, strong)UISegmentedControl *segement;
@property (nonatomic, strong)UIScrollView *scrollView;
@end

@implementation CollectingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"我喜欢的";
    [self setScrollView];
    [self creatSegmentControl];
}
- (void)setScrollView {
        UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 30, self.view.frame.size.width, self.view.frame.size.height - 30)];
    OneTableView *tableOne = [[OneTableView alloc] initWithFrame:CGRectMake(0, 0, scrollView.frame.size.width, scrollView.frame.size.height)];
    tableOne.pushDelegate = self;
    TwoTableView *tableTwo = [[TwoTableView alloc] initWithFrame:CGRectMake(self.view.bounds.size.width, 0, scrollView.frame.size.width, scrollView.frame.size.height)];
    tableTwo.pushTWODelegate = self;
    scrollView.bounces = NO;
    scrollView.pagingEnabled = YES;
    scrollView.directionalLockEnabled = YES;
    scrollView.delegate = self;
    scrollView.contentSize = CGSizeMake(self.view.frame.size.width * 2, 0);
    scrollView.showsHorizontalScrollIndicator = NO;
    [self.view addSubview:scrollView];
    _scrollView = scrollView;
    [_scrollView addSubview:tableOne];
    [_scrollView addSubview:tableTwo];
}
- (void)creatSegmentControl {
    _segement = [[UISegmentedControl alloc] initWithItems:@[@"案例", @"攻略"]];
    _segement.frame = CGRectMake(90, 0, self.view.bounds.size.width-180, 30);
    _segement.selectedSegmentIndex = 0;
    [self.segement  addTarget:self action:@selector(click:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:_segement];
    }

-(void)click:(UISegmentedControl *)sender {
    NSInteger index = sender.selectedSegmentIndex;
    if (index == 0) {
        _scrollView.contentOffset = CGPointMake(0, self.view.bounds.size.height);
    } else {
        _scrollView.contentOffset = CGPointMake(self.view.bounds.size.width, self.view.bounds.size.height);
    }
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    NSInteger i = self.scrollView.contentOffset.x / self.view.bounds.size.width;
    if (i == 0) {
        self.segement.selectedSegmentIndex = 0;
    }else{
        self.segement.selectedSegmentIndex = 1;
    }
}

- (void)pushViewController:(UIViewController *)viewController id:(NSNumber *)id {
    self.hidesBottomBarWhenPushed= YES;
    [self.navigationController pushViewController:viewController animated:YES];
}
- (void)pushTWOViewController:(UIViewController *)viewController id:(NSNumber *)id {
    self.hidesBottomBarWhenPushed= YES;
    [self.navigationController pushViewController:viewController animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
